<?php
    namespace app\admin\model;
    use think\Model;
    use think\request;
    use think\Db;

    
    class Student extends Model
    {

        public function s_list(){
            $map =[];
            $request = Request::instance();
            $data = $this->where($map)->order('User_id asc')->select();
            return $data;
        }

        public function insert($data){
            $username = $data['Name'];
            $password = $data['Password'];
            $relname = $data['Relname'];
            $class = $data['Class'];

            $result = Db::table('student')->insert([
                'User_name'=>$username,
                'User_password'=>$password,
                'Class'=>$class,
                'Rel_name'=>$relname
            ]);

            if ($result) {
                return 1; //新添成功
            } else {
                return 2; //新添失败
            }
        }

        public function updata($data){
            $username = $data['Name'];
            $password = $data['Password'];
            $relname = $data['Relname'];
            $class = $data['Class'];
            $sid = $data['s_id'];

            $result = Db::table('student')->where('User_id', $sid)->Update([
                'User_name'=>$username,
                'User_password'=>$password,
                'Class'=>$class,
                'Rel_name'=>$relname
            ]);
        //返回控制器
        if ($result) {
            return 1; //更新成功返回1
        } else {
            return 2; //更新失败返回2
        }
        }

    }
?>